Строковый метод translate позволяет заменять или удалять несколько символов в строке за один раз. Это похоже на множественные вызовы метода replace.
```python import string
s = "Hello, world!" print(s.translate(str.maketrans("", "", string.punctuation))) # Hello world ```
Метод translate ожидает «таблицу перевода», которую мы создаем с помощью вспомогательного метода класса maketrans.
Третий аргумент (string.punctuation в примере) — это строка символов, которые мы хотим удалить.
Значение string.punctuation включает в себя следующие символы: !#$%&'()*+,-./:;?@[\]^_{|}~`
Суть шпаргалки заключается в том, что она демонстрирует, как эффективно удалить все стандартные знаки препинания из строки в Python, используя комбинацию методов str.maketrans для создания инструкции по удалению и str.translate для применения этой инструкции к строке.
Строковый метод translate позволяет заменять или удалять несколько символов в строке за один раз. Это похоже на множественные вызовы метода replace.
```python import string
s = "Hello, world!" print(s.translate(str.maketrans("", "", string.punctuation))) # Hello world ```
Метод translate ожидает «таблицу перевода», которую мы создаем с помощью вспомогательного метода класса maketrans.
Третий аргумент (string.punctuation в примере) — это строка символов, которые мы хотим удалить.
Значение string.punctuation включает в себя следующие символы: !#$%&'()*+,-./:;?@[\]^_{|}~`
Суть шпаргалки заключается в том, что она демонстрирует, как эффективно удалить все стандартные знаки препинания из строки в Python, используя комбинацию методов str.maketrans для создания инструкции по удалению и str.translate для применения этой инструкции к строке.
Mr. Durov launched Telegram in late 2013 with his brother, Nikolai, just months before he was pushed out of VK, the Russian social-media platform he founded. Mr. Durov pitched his new app—funded with the proceeds from the VK sale—less as a business than as a way for people to send messages while avoiding government surveillance and censorship.
China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.